﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _04用户交互
{
    public  class LineJig:EntityJig
    {
        private Point3d jStartPoint; //直线的起点
        private Point3d jEndPoint; //直线的终点
        private string jPromtStr; //提示信息
        private string[] jKeywords; //交互关键字
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="startPoint">起点</param>
        /// <param name="promtStr">提示信息</param>
        /// <param name="keywords">交互关键字</param>
        public LineJig(Point3d startPoint, string promtStr, string[] keywords)
            : base(new Line())
        {
            jStartPoint = startPoint;
            ((Line)Entity).StartPoint = jStartPoint;
            jPromtStr = promtStr;
            jKeywords = keywords;
        }
        protected override bool Update()
        {
            ((Line)Entity).EndPoint = jEndPoint;
            return true;
        }

        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            //声明提示信息类
            JigPromptPointOptions jppo = new JigPromptPointOptions(jPromtStr);
            //添加关键字
            for (int i = 0; i < jKeywords.Length; i++)
			{
                jppo.Keywords.Add(jKeywords[i]);

			}
            char space = (char)32;
            jppo.Keywords.Add(space.ToString());
            //设置获取的信息类型
            jppo.UserInputControls = UserInputControls.Accept3dCoordinates;
            //取消系统自动添加的关键字提示信息
            jppo.AppendKeywordsToMessage = false;
            PromptPointResult pr = prompts.AcquirePoint(jppo);
            jEndPoint = pr.Value;
            return SamplerStatus.NoChange;
        }
        /// <summary>
        /// 返回图形对象
        /// </summary>
        /// <returns>Entity</returns>
        public Entity GetEntity()
        {
            return Entity;
        }
    }
}
